<?php


namespace app\cms\admin\controller\config;


use app\cms\model\oauthConfigModel;
use iflow\auth\Authorize\AuthAnnotation;
use iflow\Response;
use iflow\Router\Controller;
use iflow\Router\implement\Request\GetMapping;
use iflow\Router\implement\Request\PostMapping;
use iflow\Router\implement\Request\DeleteMapping;

#[Controller('%cmsAdmin%/oauth_config')]
class oauthConfig
{
    #[GetMapping]
    #[AuthAnnotation('oauthConfig', 'oauthConfigReadWrite|oauthConfigRead')]
    public function get(string $config_name): Response
    {
        return (new oauthConfigModel()) -> getConfigList($config_name);
    }

    #[PostMapping('create')]
    #[AuthAnnotation('oauthConfig', 'oauthConfigReadWrite|oauthConfigWrite')]
    public function create(string $config_name, array $config): Response
    {
        return (new oauthConfigModel()) -> addConfig($config_name, $config);
    }

    #[PostMapping('update/<[0-9]{1,8}:config_id>')]
    #[AuthAnnotation('oauthConfig', 'oauthConfigReadWrite|oauthConfigWrite')]
    public function update(int $config_id, string $config_name, array $config): Response
    {
        return (new oauthConfigModel()) -> updateConfig($config_id, $config_name, $config);
    }

    #[DeleteMapping('delete/<[0-9]{1,8}:config_id>')]
    #[AuthAnnotation('oauthConfig', 'oauthConfigReadWrite|oauthConfigWrite')]
    public function delete(int $config_id): Response
    {
        return (new oauthConfigModel()) -> deleteConfig($config_id);
    }
}


